<?php

namespace app\admin\model\chase;

use think\Model;

class TeacherClasses extends Model
{
    public static function createOrUpdate($teacher_id, $classes)
    {
        self::deleteClasses($teacher_id);
        $data = self::datas($teacher_id, $classes);
        self::insertAll($data);
    }

    public static function deleteClasses($teacher_id)
    {
        return self::where('teacher_id', $teacher_id)->delete();
    }

    public static function getClasses($teacher_id)
    {
        return self::where('teacher_id', $teacher_id)->column('class_id');
    }

    public static function datas($teacher_id, $classes)
    {
        $data = [];
        foreach ($classes as $val) {
            $data[] = [
                'teacher_id' => $teacher_id,
                'class_id' => $val
            ];
        }
        return $data;
    }

}
